package us.sunrisemorning.kancolleautoplay.data.util;

import cn.hutool.core.io.FileUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;

import java.nio.charset.StandardCharsets;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class ReadFromKCPSK {

    public static final String SIMPLE_PAGES_FILE = "SimplePages.json";
    public static final String SIMPLE_LINKS_FILE = "SimpleLinks.json";
    public static final String POINTS_FILE = "points.json";
    public static final String PATTERNS_FILE = "patterns.json";

    public static void showKeys(String filePath) {
        Set<String> keys = new HashSet<>();
        JSONArray data = JSONUtil.readJSONArray(FileUtil.file(filePath), StandardCharsets.UTF_8);
        for (int i = 0; i < data.size(); i++) {
            JSONObject obj = data.getJSONObject(i);
            keys.addAll(obj.keySet());
        }
        System.out.println(JSONUtil.parse(keys));
    }

    public static <T> List<T> readFile(String filePath, Class<T> bean) {
        return JSONUtil.toList(FileUtil.readString(filePath, StandardCharsets.UTF_8), bean);
    }

    public static void main(String[] args) {
        String basePath = "D:\\KanCollePlayerSimulatorKai\\data\\";
//        showKeys(basePath + SIMPLE_PAGES_FILE);
//        List<SimplePage> data = readFile(basePath + SIMPLE_PAGES_FILE, SimplePage.class);
//        System.out.println(JSONUtil.parse(data));
//        showKeys(basePath + SIMPLE_LINKS_FILE);
//        List<SimpleLink> data = readFile(basePath + SIMPLE_LINKS_FILE, SimpleLink.class);
//        System.out.println(JSONUtil.parse(data));

        showKeys(basePath + PATTERNS_FILE);
    }
}
